package com.utf999.qiangmanger.entity.orm;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.utf999.qiangmanger.entity.UUIDEntity;

/**
 * 店面服务人员。包括店面管理员都在这里
 * @author yinwenjie
 * 
 * @index unique(storeuser_workNumber, companyid , storeid , workNumber)
 */
@Entity
@Table(name="B_StoreUser")
public class StoreUserEntity extends UUIDEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3918416692472902082L;
	
	/**
	 * 所属店面
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="storefront" , nullable=false)
	private StorefrontEntity storefront;
	
	/**
	 * 所属公司（冗余信息），方便查询
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="company" , nullable=false)
	private CompanyEntity company;
	
	/**
	 * 用户名信息(一般是工号)
	 * 用户这个用户使用手机端进行登录
	 */
	@Column(name="userName" , length=128 , nullable=false , unique=true)
	private String userName;
	
	/**
	 * 真实姓名
	 */
	@Column(name="realName" , length=128 , nullable=false)
	private String realName;
	
	/**
	 * 加密后的用户登录密码
	 */
	@Column(name="encodePassword" , length=128 , nullable=false)
	private String encodePassword;
	
	/**
	 * 员工工号
	 */
	@Column(name="workNumber" , length=128 , nullable=false)
	private String workNumber = "";
	
	/**
	 * 创建（加入店面）的时间
	 */
	@Column(name="joinTime" , nullable=false)
	private Date joinTime = new Date();
	
	/**
	 * 用户状态。不能做真删除。只能做逻辑删除<br>
	 * 1、正常
	 * 0、不正常
	 */
	@Column(name="status" , nullable=false)
	private Integer status = 1;
	
	/**
	 * 这个用户所属的分组信息。
	 */
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="B_StoreUserGroupMapping" , joinColumns={@JoinColumn(name="user_id")} , inverseJoinColumns={@JoinColumn(name="group_id")})
	private Set<StoreUserGroupEntity> groups;
	
	public StorefrontEntity getStorefront() {
		return storefront;
	}

	public void setStorefront(StorefrontEntity storefront) {
		this.storefront = storefront;
	}

	public CompanyEntity getCompany() {
		return company;
	}

	public void setCompany(CompanyEntity company) {
		this.company = company;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getWorkNumber() {
		return workNumber;
	}

	public void setWorkNumber(String workNumber) {
		this.workNumber = workNumber;
	}

	public Date getJoinTime() {
		return joinTime;
	}

	public void setJoinTime(Date joinTime) {
		this.joinTime = joinTime;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Set<StoreUserGroupEntity> getGroups() {
		return groups;
	}

	public void setGroups(Set<StoreUserGroupEntity> groups) {
		this.groups = groups;
	}
	
	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getEncodePassword() {
		return encodePassword;
	}

	public void setEncodePassword(String encodePassword) {
		this.encodePassword = encodePassword;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.entity.UUIDEntity#getUniqueKey()
	 */
	@Override
	public String getUniqueKey() {
		return "uid";
	}
}